//
//  CarResourceModel.m
//  Shuaiche
//
//  Created by zzs on 2017/10/19.
//  Copyright © 2017年 zzs. All rights reserved.
//

#import "CarResourceModel.h"
#import "CarPicModel.h"
//#import "CarColorModel.h"
#import "SCConstants.h"
//#import "PrepareItemModel.h"
#import "Config.h"
#import "NSString+SCStringHandle.h"
@implementation CarResourceModel

// 返回容器类中的所需要存放的数据类型 (以 Class 或 Class Name 的形式)。
+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{@"carMainPic" : [CarPicModel class],
             @"display":[CarPicModel class],
             @"carPics":[CarPicModel class],
//              @"color":[CarColorModel class],
//             @"prepareItemProdRO":[PrepareItemModel class],
             };
}

- (NSString *)seriesName {
    if (!_seriesName.length) {
        NSArray *array = [_carName componentsSeparatedByString:@"#"];
        if (array.count > 2) {
            _seriesName = array[1];
        }
    }
    return _seriesName;
}

- (NSString *)carMainPicPath {
    if (!_carMainPicPath) {
        NSArray *pics = [_unionPics componentsSeparatedByString:@","];
        
        if (_listUnionId > 0) {
            for (NSString *pic in pics) {
                NSArray *picArray = [pic componentsSeparatedByString:@"#"];
                if (picArray.count > 1) {
                    NSString *uid = picArray.firstObject;
                    if (uid.integerValue == _listUnionId) {
                        _carMainPicPath = picArray.lastObject;
                        break;
                    }
                }
            }
        } else {
            BOOL isFind = NO;
            
            NSArray *array = [Config sharedConfig].scUserUnionIds;
            for (NSNumber *num in array) {
                for (NSString *pic in pics) {
                    NSArray *picArray = [pic componentsSeparatedByString:@"#"];
                    if (picArray.count > 1) {
                        NSString *uid = picArray.firstObject;
                        if (uid.integerValue == num.integerValue) {
                            _carMainPicPath = picArray.lastObject;
                            isFind = YES;
                            break;
                        }
                    }
                }
                if (isFind) break;
            }
        }
        if (!_carMainPicPath) {
            _carMainPicPath = _mainPic;
        }
    }
    return  _carMainPicPath;
}

- (id)valueForUndefinedKey:(NSString *)key{
    NSLog(@"UndefinedKey is:%@",key);
    return nil;
}

@end
